package com.lingnan.tijian.dto;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.json.JsonMapper;

import java.util.List;

public class ApiResponse<T> {

    private Integer status;
    private String desc;
    //定义泛型，需要在类上声明泛型
    private T data;

    public String toJSONString(){
        String jsonStr=null;
        try{
            jsonStr=new ObjectMapper().writeValueAsString(this);
        }catch (Exception e){
            e.printStackTrace();
        }
        return jsonStr;
    }

    //通用操作：成功
    public final static Integer SUCCESS_STATUS=200;
    public final static String SUCCESS_DESC="成功";

    public ApiResponse(Integer status,String desc){
        this.status=status;
        this.desc=desc;
    }

    public ApiResponse(Integer status,String desc,T data){
        this.status=status;
        this.desc=desc;
        this.data=data;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
